<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>职工培训管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="../../layuimini/lib/layui-v2.5.5/css/layui.css" media="all" />
    <link rel="stylesheet" href="../../layuimini/css/public.css" media="all" />
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <table class="layui-hide" id="UnSignTable" lay-filter="UnSignFilter"></table>

        </div>
    </div>

    <script type="text/html" id="UnSignTableToolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm layui-btn-sucess" lay-event="refresh">
                刷新
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="export">
                导出全部数据
            </button>
        </div>
    </script>

    <script type="text/html" id="HelpSign">
        <!--代签-->
    <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="helpsign">为其代签</a>
    </script>

    <script type="text/html" id="SignDiaLog">
        <div class="layui-row">
            <div class="layui-col-md8 layui-col-offset2" style="text-align: center;" id="dialog_text"></div>
        </div>
    </script>
    <script src="../layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../layuimini/js/lay-config.js" charset="utf-8"></script>
    <script>
        layui.use(['common', 'table', 'layer', 'form', 'jquery'], function (res) {
            var common = layui.common
            table = layui.table
            $ = layui.jquery
            common.axios('/attendance/attendance/listUnattendance', 'get', null, function (res) {
                console.log(res)
            })
            UnSignTable = table.render({
                elem: "#UnSignTable",
                url: common.api + '/attendance/attendance/listUnattendance',
                where: {
                    token: common.getToken
                },
                toolbar: '#UnSignTableToolbar',
                title: '未签到人员',
                limits: [1, 5, 10, 15, 20],
                limit: 15,
                page: true,
                skin: 'row',
                even: true,
                cols: [
                    [{
                            field: 'id',
                            title: '员工ID',
                            minWidth: 300,
                            sort: true,
                            align: 'center'
                        },
                        {
                            field: 'name',
                            title: '员工名称',
                            minWidth: 300,
                            sort: true,
                            align: 'center'
                        },
                        {
                            title: '代签',
                            minWidth: 200,
                            toolbar: '#HelpSign',
                            align: 'center'
                        }
                    ]
                ],
                parseData: function (res) {
                    //console.log(res)
                    if (res.code != 200) {
                        common.login()
                    }
                    return {
                        code: res.code,
                        msg: res.msg,
                        count: res.data.total,
                        data: res.data.list
                    }
                },
                response: {
                    statusCode: 200, //重新规定成功的状态码为 200，table 组件默认为 0
                },
                request: {
                    pageName: 'page', //页码的参数名称，默认：page
                    limitName: 'size', //每页数据量的参数名，默认：limit
                },
                initSort: {
                    field: 'id',
                    type: 'asc',
                },
            })
            table.on('tool(UnSignFilter)', function (obj) {
                if (obj.event === 'helpsign') {
                    console.log(obj.data)
                    showHelpSignDialog(obj.data)
                }
            })

            function showHelpSignDialog(data) {
                //弹出代签对话框
                var dialog = layer.confirm(
                    '确定为员工' + data.name + '代签?', {
                        skin: 'layui-layer-admin',
                        shade: 0.1,
                    },
                    function (i) {
                        var index = layer.load(2)
                        common.axios('/attendance/insertUn',
                            'post', {id:data.id},
                            function (res) {
                                if (res != null) {
                                    layer.close(index)
                                    layer.msg('代签成功！', {
                                        icon: 1
                                    })
                                    UnSignTable.reload({
                                        url:common.api+'/attendance/attendance/listUnattendance'
                                    })
                                } else {
                                    layer.close(index)
                                    layer.msg('代签失败', {
                                        icon: 2
                                    })
                                }
                            },
                            function(){
                                layer.close(index)
                            },{id:data.id})
                    }
                )
            }
        })
    </script>
</body>

</html>